//
//  NXMServerViewController.swift
//  AnneKit-Swift
//
//  Created by 宁小陌 on 2021/2/3.
//  Copyright © 2021 宁小陌. All rights reserved.
//

import UIKit
import SwiftyJSON
import SnapKit

class NXMServerViewController: UIViewController, UITableViewDataSource, UITableViewDelegate {
    ///数据源
    lazy var dataArray: [String] = ["MVC", "MVP", "MVVM"]
    override func viewDidLoad() {
        super.viewDidLoad()
        // Do any additional setup after loading the view.
        
//        self.navigationItem.title = "商家"
        //获取数据源
        
        
        NXMUILog(parameter: kStatusBarHeight)
        self.view.backgroundColor = UIColor.kViewColorNormal
        if isIphoneX() {
            NXMUILog(parameter: "isIphoneX")
        }else{
            NXMUILog(parameter: "isIphoneX个锤子")
        }

        
        let tableView = UITableView(frame: view.bounds, style: .plain)
        tableView.backgroundColor = UIColor.white;
        view.addSubview(tableView)
        tableView.dataSource = self
        tableView.delegate = self
        tableView.snp.makeConstraints { (make) in
            make.edges.equalToSuperview()
        }
    }
    
    func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
        return dataArray.count+20
    }
    
    // 设置cell高度
    func tableView(_ tableView: UITableView, heightForRowAt indexPath: IndexPath) -> CGFloat {
        return 60.0
    }
        // UITableViewCell
    func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
        let cellid = "testCellID"
        var cell = tableView.dequeueReusableCell(withIdentifier: cellid)
        if cell==nil {
            cell = UITableViewCell(style: .subtitle, reuseIdentifier: cellid)
        }
        
        cell?.textLabel?.text = "这个是标题~"
        cell?.detailTextLabel?.text = "这里是内容了油~"
        if indexPath.row<3 {
            cell?.textLabel?.text = dataArray[indexPath.row]
        }

        cell?.imageView?.image = UIImage(named:"mine_btn_dianping")
        return cell!
    }
      
    //MARK: UITableViewDelegate
    // 选中cell后执行此方法
    func tableView(_ tableView: UITableView, didSelectRowAt indexPath: IndexPath) {
        print(indexPath.row)
        switch indexPath.row {
        case 0:
            self.navigationController?.pushViewController(MVCViewController.init(), animated: true)
        case 1:
            self.navigationController?.pushViewController(MVPViewController.init(), animated: true)
        case 2:
            self.navigationController?.pushViewController(MVVMViewController.init(), animated: true)
        default:
            break
        }
        self.tabBarController?.hidesBottomBarWhenPushed = true
    }
}

